<?php
//按钮
namespace app\adminbackstage\model;

use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Button extends Model{

    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }
    
    //按钮查询
    public function buttonList($where,$page=1,$num=10){
        $list = $this::name('button')
        ->field('b.id as id,me.menu_name as menu_name,b.b_name as b_name,b.b_iden as b_iden,b.mid')
        ->alias('b')
        ->leftjoin('menu me','b.mid = me.id')
        ->where($where)
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
    }
    
    //按钮数
    public function buttonCount($where) {
        return $this::name('button')
        ->field('b.id as id,me.menu_name as menu_name,b.b_name as b_name,b.b_iden as b_iden,b.mid')
        ->alias('b')
        ->leftjoin('menu me','b.mid = me.id')
        ->where($where)
        ->count();
    }

    //按钮修改
    public function buttonEdit($id,$update){
        $in = $this::update($update, ['id' => $id]);
        return $in;
    }
    
    //角色权限完全清除修改
    public function buttonEditE($rid,$update){
        $in = $this::update($update, ['rid' => $rid]);
        return $in;
    }

    //按钮添加
    public  function buttonAdd(array $data){
        return self::create($data);
    }
  
}
